import java.io.*;
import java.net.*;
import java.util.*;
import java.security.Security;
import java.security.Provider;
import javax.net.ssl.*;
import local.util.MyPrint;
import java.text.DecimalFormat;

import local.util.MyStringFormat;
import local.util.MyPrint;

public class RealIndexData {    

    private static boolean debug = false;
    private static boolean save = false;
    private String myUrl = null;
    private String urlReturnString = new String();
    private Vector urlReturnVector= new Vector(10);
    private String startString= null;
    private String endString  = null;

    public static void main (String[] args) {

	String url_return_string = null;
	Vector url_return_vector = new Vector ();

	RealIndexData mydl = new RealIndexData ();
	HttpDataLoader dl = new HttpDataLoader ();

	dl.setUrl("http://www.mrci.com/qpnight.asp");
	dl.connectToUrl();
	url_return_string = dl.getUrlReturnString();

	url_return_vector = mydl.stringToVector (url_return_string);
	mydl.setStartString("S & P 500(CME)(Globex)");
	mydl.setEndString("30-Yr T-Bonds a/c/e (CBOT)");
	url_return_vector = mydl.selectUsefulElements (url_return_vector);
	//url_return_vector = mydl.deselectElement (url_return_vector, "Industries");
	//url_return_vector = mydl.deselectElement (url_return_vector, "&#183");
	//url_return_vector = mydl.deselectElement (url_return_vector, ":");
	//MyPrint.printVector(url_return_vector,1);
	MyPrint.printVector(url_return_vector,10);

    }

    public Vector stringToVector (String input) {

	Vector url_return_head = new Vector ();
	Vector url_return_vector = new Vector ();
	String temp = null;
	String element = null;
	StringTokenizer tokens = new StringTokenizer(input, "\n");
		
	while (tokens.hasMoreTokens()) {
	    element =  tokens.nextToken();
	    element=element.trim();
	    element=element.replaceAll("\t","");
	    if (element != null && !element.equals("")) {
		url_return_vector.addElement(element);
	    }
	}
	return url_return_vector;
    }

    public void setStartString ( String start_str ) {
	startString = start_str;
    }

    public void setEndString ( String end_str ) {
	endString = end_str;
    }

    public Vector selectUsefulElements (Vector v_in) {

	Vector v_out = new Vector (10);
	String text = null;
	Enumeration penum = v_in.elements();
       
	while ( penum.hasMoreElements()) {

	    text = (String)penum.nextElement();
	    if (text.startsWith(startString)) {
		v_out.addElement(text);
		break;
	    }
	}
	
	while ( penum.hasMoreElements() ) {
	    text = (String)penum.nextElement();
	    if (text.startsWith(endString)) {
		break;
	    }
	   	    
	    if ( ! (text.startsWith("<") )) {
		v_out.addElement(text);
	    }
	}
	
	return v_out;
    }

    public Vector deselectElement (Vector v_in, String d_element) {

	Vector v_out = new Vector (10);
	String text = null;
	Enumeration penum = v_in.elements();
       
	while ( penum.hasMoreElements()) {

	    text = (String)penum.nextElement();

	    if (!text.startsWith(d_element)) {
		v_out.addElement(text);
	    }
	}
	return v_out;
    }

    public void insertIntoDataBase( String query_string) {

	DataBaseInsert myInsert = new DataBaseInsert();	
	
	myInsert.setQueryString(query_string);
	myInsert.insertData();

    }         
}








